September 13, 2019

Time Serie of Hang Seng Index

Introduction

Hang Seng Index (HSI) is a stock market index in Hong Kong showing the market price movement. This report is going to plot the daily HKI time serie in the period between 13 March and 5 June 2019.

"quantmod" package is used and index data was downloaded from "yahoo" websit.

R Code

library(plotly)
library(quantmod)
library(dplyr)
## set period
from.dat <- as.Date("03/13/19", format = "%m/%d/%y")
to.dat <- as.Date("06/06/19", format = "%m/%d/%y")
## download HSI price data
suppressWarnings(getSymbols("HSI", src = "yahoo", from = from.dat, 
                            to = to.dat))

dHSI <- suppressWarnings(to.daily(HSI))
HSIClose <- Cl(dHSI)

HSIClose <- as.data.frame(HSIClose)

HSIClose <- mutate(HSIClose, time = rownames(HSIClose))

plot_ly(HSIClose, x = ~time, y = ~HSI.Close, type = "area")
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:xts':
## 
##     first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
## 
## This message is shown once per session and may be disabled by setting 
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## [1] "HSI"

Output Graph

## Warning: 'area' objects don't have these attributes: 'x', 'y'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'r', 't', 'marker', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'